//
//  VideoTableViewCell.m
//  BlackCool
//
//  Created by cocoazxj@163.com on 15/4/29.
//  Copyright (c) 2015年 handcool. All rights reserved.
//

#import "VideoTableViewCell.h"
#import "UIView+Ext.h"

@interface VideoTableViewCell()
@property (nonatomic, strong) UIView *mLine;
@end

@implementation VideoTableViewCell

+ (VideoTableViewCell *)cellWithTable:(UITableView *)table
{
    static NSString *identifier = @"identifier";
    VideoTableViewCell *cell = [table dequeueReusableCellWithIdentifier:identifier];
    if(!cell)
    {
        cell = [[VideoTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        UIView *line = [[UIView alloc] init];
        line.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:line];
        self.mLine = line;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.imageView setFrame:CGRectMake(10, 10, 100, self.contentView.h- 20)];
    [self.textLabel setFrame:CGRectMake(120, 10, self.contentView.w - 120, 21)];
    [self.detailTextLabel setFrame:CGRectMake(120, 31, self.contentView.w - 120, 21)];
    [self.mLine setFrame:CGRectMake(0, self.contentView.h - 1, self.contentView.w, 1)];
}

- (void)setVideoModel:(VideoModel *)videoModel
{
    _videoModel = videoModel;
    self.textLabel.text = videoModel.name;
    self.detailTextLabel.text = [NSString stringWithFormat:@"%d分钟",videoModel.length];
    
#warning 如果没有设置默认图片,图片可能会下载了;但是不会显示在UITableViewCell中.
//    [self.imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.0.77:8080/MJServer/%@",videoModel.image]]];
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.0.77:8080/MJServer/%@",videoModel.image]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
}
@end
